package top.gytf.unifiedcall.model.detail;

import cn.hutool.core.util.ClassUtil;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.Collection;
import java.util.Set;

import static java.util.stream.Collectors.toSet;

/**
 * 简单实现
 */
@Data
@AllArgsConstructor
public class SimpleUnifiedCallPackageDetail implements UnifiedCallPackageDetail {
    public static SimpleUnifiedCallPackageDetail with(UnifiedCallPackageDetail detail) {
        return new SimpleUnifiedCallPackageDetail(detail.getName(), detail.getVersion(), detail.getClients());
    }

    private String name;
    private Version version;
    private Set<Class<?>> clients;

    public SimpleUnifiedCallPackageDetail(String name, String version, Set<Class<?>> clients) {
        this(name, Version.valueOf(version), clients);
    }

    public void setVersion(String version) {
        this.version = Version.valueOf(version);
    }

    public void setClients(Collection<String> clients) {
        this.clients = clients.stream().map(ClassUtil::loadClass).collect(toSet());
    }
}
